// 让所有input失去焦点
export const blurAllInputs = (container = document) => {
  // const isMiniProgram = typeof wx !== 'undefined' && wx.createSelectorQuery;// 微信小程序环境

  let environmentType = null;
  if (typeof window !== 'undefined') {
    if (typeof window.plus !== 'undefined') {
      // plus.webview 运行的环境
      environmentType = 'window_plus_has';
    } else {
      // 普通浏览器环境(h5)
      environmentType = 'window_plus_no';
    }
  } else {
    // app-plus环境，例如uni-app直接安装的APK/APP环境
    environmentType = 'app_plus';
  }

  if (environmentType === 'window_plus_has') {
    const inputs = container.querySelectorAll('input');
    inputs.forEach(input => input.blur());
  } else if (environmentType === 'window_plus_no') {
    // 普通浏览器环境
    const inputs = container.querySelectorAll('input');
    inputs.forEach(input => input.blur());
  } else if (environmentType === 'app_plus') {
    // 真机运行环境
    const query = uni.createSelectorQuery();
    query.selectAll('input').fields({
      node: true,
      context: true
    }, (res) => {
      if (res && res.length > 0) {
        res.forEach(input => {
          if (input.node && input.blur) {
            input.blur();
          }
        });
      }
    }).exec();
  }
};
